﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Text;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.WebControls;

namespace WinnerCMS.WebControls.BootStrap
{
    public class Breadcrumb : ListControl
    {
        protected override void Render(HtmlTextWriter writer)
        {
            StringBuilder sb = new StringBuilder("<ol class=\"breadcrumb\">");

            for (int index = 0; index < this.Items.Count; index++)
            {
                ListItem item = this.Items[index];


                if (string.IsNullOrWhiteSpace(item.Value))
                {
                    sb.AppendFormat("\r\n<li>{0}</li>", item.Text);
                }
                else
                {
                    sb.AppendFormat("\r\n<li><a href=\"{1}\">{0}</a></li>", item.Text, item.Value);
                }
            }
            sb.AppendLine("</ol>");
            writer.Write(sb.ToString());
        }

        public void InitData(string data)
        {
            this.Items.Clear();
            var arr = data.Split(new[] { ',', '|' });

            foreach (var item in arr)
            {
                this.Items.Add(new ListItem(item, ""));
            }
        }

    }
    public class BreadcrumbDesigner : ControlDesigner
    {

        public BreadcrumbDesigner()
        {

        }

        private WinnerCMS.WebControls.BootStrap.Breadcrumb _breadcrumb;
        public override void Initialize(IComponent component)
        {
            this._breadcrumb = (WinnerCMS.WebControls.BootStrap.Breadcrumb)component;
            base.Initialize(component);
        }

        public override string GetDesignTimeHtml()
        {
            StringWriter sw = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);

            //Table tb = new Table();
            //tb.CellPadding = 0;
            //tb.CellSpacing = 0;

            //TableRow row = new TableRow();
            //TableCell cl = new TableCell();
            //System.Web.UI.WebControls.TextBox box = new System.Web.UI.WebControls.TextBox();
            //box.Width = new Unit("100px");
            //box.Text = _Breadcrumb.Value;
            //cl.Controls.Add(box);
            //System.Web.UI.WebControls.Image _img = new System.Web.UI.WebControls.Image();
            //_img.ImageUrl = _Breadcrumb.CalendarResource + "Calendar.gif";
            //_img.ImageAlign = ImageAlign.Top;
            //_img.BorderWidth = new Unit("0px");

            //cl.Controls.Add(_img);
            //cl.Wrap = false;
            //row.Cells.Add(cl);
            //tb.Rows.Add(row);

            //tb.RenderControl(htw);
            return sw.ToString();
        }

    }
}